<?php

namespace App\Models;
class SupplyModel extends ToyModel
{
    protected $table = 'supplier';
    protected $primaryKey = 'ID';
    protected $guarded = [];

    /**
     * 获取模型
     * @param $request
     * @return mixed
     */
    public static function getModel($request): mixed
    {
        $Model = self::where('ID', '>', 0);
        if ($request->input('CName'))
            $Model = $Model->where('CName', 'like', '%'.$request->input('CName').'%');
        if ($request->input('room'))
            $Model = $Model->where('room', 'like', '%'.$request->input('room').'%');
        if ($request->input('authed')) {
            $supplyIds = UserModel::where('sid', '>', 0)->pluck('sid');
            $Model = $Model->whereIn('ID', $supplyIds);
        }
        return $Model;
    }
}
